<?php

header('content-type:text/html;charset=utf-8');
session_start();
require 'config.php';
error_reporting(5);
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(0);


//身份验证
session_start();
if (!isset($_SESSION['login'])) {
	header('Refresh:3;url=login/index.php');
	echo "你还没有登陆！";
	die();
}


$gsn=$_POST['gsn'];
$lx=$_POST['lx'];
$fl=$_POST['fl'];
$ejfl=$_POST['ejfl'];
$ms=$_POST['ms'];
$xq=$_POST['xq'];
$sell=$_POST['sell'];
$zt=$_POST['zt'];
$price=$_POST['price'];
$yuanjia=$_POST['yuanjia'];
$kucun=$_POST['kucun'];

if($gsn==null||$xq==null||$price==null||$yuanjia==null){
header('Refresh:1;url=goods_add.php');
	echo '请将信息填写完整!';
	die();
}

// 获取userid和user地址
$email=$_SESSION['login'];
$query_email="SELECT * FROM users WHERE `uemail`='$email'";
$result_email=mysqli_query($config,$query_email);
$row_email=mysqli_fetch_array($result_email);
// $id=$row_email['userid'];


// 获取时间
$pub_time=Date('Y-m-d H:i:s');



// 图片上传


$filename = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];

//将服务器上的临时文件移动到指定目录下

//使用该方法move_uploaded_file($tmp_name , $destination)

move_uploaded_file($tmp_name , "D:phpstudy_pro/WWW/school/images/goods/$fl/$ejfl/".$filename);

// echo $filename;
// exit();

// 插入数据
$sql = "INSERT INTO goods (goodsid,goodsname,leixing,bigtypeid,smalltypeid,xinghao,intro,sell,zhuangtai,price,yuanjia,kucun,pub_time,address,userid,picture,hot,state)
values (null,'".$gsn."','".$lx."','".$fl."','".$ejfl."','".$ms."','".$xq."','".$sell."','".$zt."','".$price."','".$yuanjia."','".$kucun."','".$pub_time."','".$row_email['uaddress']."','".$row_email['userid']."','".$filename."','0','1')";
mysqli_query($config,$sql) or die ('新增错误：'.mysqli_error($config));
// var_dump($fl);
// var_dump($ejfl);
// var_dump($row_email);

echo ('<script type="text/javascript">alert("商品发布成功！等待审核");
     			window.location.href = "shenhe.php";
     			</script>');
	die();

?>